//package com.mt.vsphere.business.vshpereApi;
//
//import com.mt.vsphere.business.bean.ItemVo;
//import com.vmware.connection.BasicConnection;
//import com.vmware.connection.Connection;
//import com.vmware.connection.VCenterSampleBase;
//import com.vmware.connection.helpers.GetMOREF;
//import com.vmware.vim25.InvalidPropertyFaultMsg;
//import com.vmware.vim25.ManagedObjectReference;
//import com.vmware.vim25.RuntimeFaultFaultMsg;
//import com.vmware.vim25.ServiceContent;
//
//import javax.net.ssl.HostnameVerifier;
//import javax.net.ssl.HttpsURLConnection;
//import javax.net.ssl.SSLSession;
//import java.util.ArrayList;
//import java.util.List;
//import java.util.Map;
//
//import static com.vmware.sso.client.utils.Utils.trustAllHttpsCertificates;
//
//
//public class Main {
//
//    private static Connection connection;
//    private static GetMOREF getMOREFs;
//    private static ServiceContent serviceContent;
//    private static String datacenter = "ha-datacenter";
//    private static String host = "192.localdomain";
//    private static String vmName = "valutal1";
//
//    public static void main(String[] args) throws Exception {
//        trustAllHttpsCertificates();
//        HostnameVerifier var1 = new HostnameVerifier() {
//            public boolean verify(String var1, SSLSession var2) {
//                return true;
//            }
//        };
//        HttpsURLConnection.setDefaultHostnameVerifier(var1);
//
//        VCenterSampleBase vCenterSampleBase = new VCenterSampleBase();
//        BasicConnection basicConnection = new BasicConnection();
//        basicConnection.setUrl("https://192.168.1.249/sdk");
//        basicConnection.setUsername("vsphere.local\\administrator");
//        basicConnection.setPassword("Mt201988.");
//
//        vCenterSampleBase.setConnection(basicConnection);
//        connection = vCenterSampleBase.connect();
//        getMOREFs = new GetMOREF(connection);
//        serviceContent = connection.getServiceContent();
//        System.out.println(connection.getServiceContent().getAbout().getFullName());
//        getAllVirtualMachine();
//    }
//
//    static void getAllVirtualMachine() {
//        try {
//
//            List<ItemVo> list = new ArrayList<>();
//            //获取数据中心的引用
//            ManagedObjectReference mrf = null;
//            Map<String,ManagedObjectReference> map = getMOREFs.inContainerByType(serviceContent.getRootFolder(),"Datacenter");
//            for (Map.Entry<String,ManagedObjectReference> DataCenterEntry:map.entrySet()){
//                ItemVo itemVo = new ItemVo(DataCenterEntry.getKey(),"数据中心","192.168.1.249");
//                list.add(itemVo);
//            }
//            list.forEach(item->{
//                System.out.println(item.getName());
//            });
//            //获取数据中心下的所有主机
//            Map<String, ManagedObjectReference> hosts =
//                    getMOREFs.inContainerByType(mrf, "HostSystem");
//            //获取指定主机的引用
//            ManagedObjectReference hostMor = hosts.get("192.localdomain");
//            //获取主机下的虚拟机数量
//            Map<String, ManagedObjectReference> vms =
//                    getMOREFs.inContainerByType(hostMor, "VirtualMachine");
//
//            System.out.println(vms.size());
//        } catch (InvalidPropertyFaultMsg invalidPropertyFaultMsg) {
//            invalidPropertyFaultMsg.printStackTrace();
//        } catch (RuntimeFaultFaultMsg runtimeFaultFaultMsg) {
//            runtimeFaultFaultMsg.printStackTrace();
//        }
//    }
//}
